;********************************************************************
;*          MultiSioAsmArm.s                                        *
;*            Multi-play Communication Library (for ARMASM)         *
;*(Timer interrupt transmission & communication data synchronization)*
;*             (exclusively for multiple interrupts)                *
;*                                                                  *
;*          Copyright (C) 1999-2001 NINTENDO Co.,Ltd.               *
;********************************************************************
    INCLUDE     AgbDefineArm.s
    INCLUDE     AgbMemoryMapArm.s
    INCLUDE     AgbSyscallDefineArm.s
    INCLUDE     AgbMacroArm.s
    AREA        Init, CODE, READONLY

    INCLUDE     MultiSioDefineArm.s


    IF :DEF: MULTI_SIO_DI_FUNC_FAST

;--------------------------------------------------------------------
;               Received data Check buffer Update Routine           -
;--------------------------------------------------------------------

    EXTERN      Ms
    GLOBAL      MultiSioRecvBufChange
    CODE32
MultiSioRecvBufChange
        stmfd   sp!, {r8-r11}

        mov     r12, #REG_BASE                      ; r12: REG_BASE
        ldr     r11, =Ms                            ; r11: &Ms
        add     r10, r11, #OFS_MS_LAST_RECV_BUF_P   ; r10: &Ms.LastRecvBufp[0]
        mov     r9,  #1                             ; r9:  1
        mov     r8,  #0                             ; r8:  0


        ; *(vu8 *)REG_IME = 0   Disables interrupt (15 clocks)

        strb    r8,  [r12, #OFFSET_REG_IME]

        ; Ms.RecvCheckBufp[i] <--> Ms.LastRecvBufp[i]

        ldmia   r10,  {r0-r1}
        stmia   r10!, {r1}
        stmia   r10!, {r0}

        ; SyncRecvFlagBak[i] = Ms.SyncRecvFlag[i]
        ; Ms.SyncRecvFlag[i] = 0

        ldrb    r0,  [r11, #OFS_MS_SYNC_RECV_FLAG]
        strb    r8,  [r11, #OFS_MS_SYNC_RECV_FLAG]

        ; *(vu8 *)REG_IME = 1   Enables interrupt

        strb    r9,  [r12, #OFFSET_REG_IME]

        ; return  Ms.SyncRecvFlag[i]

        ldmfd   sp!, {r8-r11}
        bx      lr

    LTORG                                           ; Creates literal pool


    ENDIF


    END

